package com.njupt.HashTable;


/**
 *
 */
public class HappyNum {

    public boolean isHappy(int n) {
        String s = String.valueOf(n);
//        if(n!=1 && s.length()<2){
//            return  false;
//        }
        s += "0";
        long result ;
        while(true){
            result = 0;
            for (int i = 0; i < s.length(); i++) {
                result += Long.valueOf(String.valueOf(s.charAt(i))) * Long.valueOf(String.valueOf(s.charAt(i)));
            }
            if(result ==1){
                return true;
            }
            s = String.valueOf(result);
        }
    }

    public static void main(String[] args) {
        HappyNum test = new HappyNum();
        System.out.println(test.isHappy(19));

    }
}
